package com.atguigu.mq.util;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class ConnectionUtil {
    public static Connection  getConnection() throws Exception {
        //获取链接工厂，初始化连接参数
        ConnectionFactory connectionFactory = new ConnectionFactory();
        //主机地址
        connectionFactory.setHost("192.168.164.128");
        //链接端口，默认为5672
        connectionFactory.setPort(5672);
        //连接虚拟主机；默认为/
        connectionFactory.setVirtualHost("/");
        //连接用户名，默认为admin
        connectionFactory.setUsername("admin");
        //连接用户密码
        connectionFactory.setPassword("admin");
        //创建连接
        Connection connection = connectionFactory.newConnection();

        return connection;
    }
}
